package simple;

import VO.Node;

/**
 * @author gh
 * @create 2021-05-26 6:34
 */
public class reverseList {
    //1递归法，2遍历法

    public Node reverse1(Node head) {
        if (head == null || head.next == null)
            return head;
        Node temp = head.next;
        Node newHead = reverse1(head.next);
        temp.next = head;
        head.next = null;
        return newHead;
    }

    public static Node reverseList2(Node node) {
        Node pre = null;
        Node next = null;
        while (node != null) {
            next = node.next;
            node.next = pre;
            pre = node;
            node = next;
        }
        return pre;
    }
}
